<?php
class promotor extends CI_Controller {
	var $titp='Promotores';
	var $url ='promotor/';

	function index(){
		redirect($this->url.'filteredgrid');
	}

	function filteredgrid(){
		$this->load->library('rapyd');

		$filter = new datafilter_library();
		$filter->label = 'B&uacute;squeda de promotores';
		$filter->db->select('*');
		$filter->db->from('promotores');

		$filter->field('input','nombre'  ,'Nombre')->attributes(array('style' => 'width:170px'));
		$filter->field('input','cedula'  ,'Cédula')->attributes(array('style' => 'width:170px'));

		$filter->buttons('reset', 'search');
		$filter->build();

		$uri = anchor($this->url.'dataedit/show/<raencode><#id#></raencode>','<#id#>');

		$grid = new datagrid_library();
		$grid->label = 'Lista de Promotores';
		$grid->per_page = 40;
		$grid->cid = '';
		$grid->source($filter);

		$grid->column('nombre','Nombre',true)->url('promotor/dataedit/show/{id}');
		$grid->column('cedula','Cédula',true);

		$grid->add_button(array('url'=>$this->url.'dataedit/create'));
		$action = "javascript:window.location.href='".site_url('/')."'";
		$grid->button('btn_reg', 'Regresar', $action, 'TR');

		$grid->build();

		$data['content'] = $filter->output.$grid->output;
		$data['head']    = $this->rapyd->head().script('jquery.js');
		$data['title']   = '';
		$this->load->view('view_ventanas_sola', $data);

	}

	function dataedit(){
		$this->load->library('rapyd');

		$edit = new dataedit_library();
		$edit->label = 'Promotores';
		$edit->back_url = site_url($this->url.'filteredgrid');

		$edit->source('promotores');

		$edit->field('input','nombre','Nombre')->rule('trim|required');
                $edit->field('dropdown','servicio','Servicio')
			->options(array(
				'' =>'Seleccionar',
				'Si'=>'Si',
				'No'=>'No'))
			->rule('required');

		$edit->field('dropdown','clase','Clase')
			->options(array(
				'' =>'Seleccionar',
				'P'=>'Permanente',
				'I'=>'Itermitente'))
			->rule('required');

		$edit->field('input','cedula','Cedula')->rule('trim|required');

		$edit->buttons('modify','save','undo','delete','back');
		$edit->build();

		$data['head']    = $this->rapyd->head();
		$data['title']   = '<h1>Ficha de promotor</h1>';
		$data['content'] = $edit;
		$this->load->view('view_ventanas_sola', $data);
	}
}
